<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url>
</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";
import {_config} from "@/js/s94_tool.js";
import s94Mjs from "s94-js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');

    if(in_right_admin('UserRealName/add')) btns['添加'] = function(){ iframe('user_real_name/edit') }
    if(in_right_admin('UserRealName/delete')) btns['彻底删除'] = function(){ app.$refs['list_url'].delete() }

    let status_config = _config('status_alias_map.user_real_name.status');
    let forms_config = {
     create_time: {label:'申请时间',name:'where[create_time][between]',config:'Y-M-D',type:'date_between',value:''},
     user_id: {label:'用户',name:'where[user_id][eq]',type:'list_id',no_table:1,config:'user/index',value:this.$get('user_id','')},
     status: {label:'状态',name:'where[status][eq]',type:'select_one',config:status_config,value:''},
    };
    let list_cols = {
      id: {name:'id', label:'ID', width:'65px', fixed:'left', type: 'hidden', order:true},
      user_head_img: {name:'user_head_img', label:'头像', width:'45px', type:'file_img'},
      user_nickname:{name:'user_nickname', label:'昵称', width:'120px'},
      name:{name:'name', label:'姓名', width:'120px'},
      id_card:{name:'id_card', label:'身份证号', width:'220px'},
      id_card_front:{name:'id_card_front', label:'正面', width:'45px', type:'file_img'},
      id_card_back:{name:'id_card_back', label:'背面', width:'45px', type:'file_img'},
      status:{name:'status', label:'状态', width:'75px',type:'select_one',config:status_config},
      admin_note:{name:'admin_note', label:'管理员备注', stayle:'width:120px;'},
      expiration_time:{name:'expiration_time', label:'过期时间', width:'165px'},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'创建时间', width:'165px'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'80px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/user_real_name/'+(is_del?'recycle':'list'),
        title: "实名认证列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
        order: 'status asc',
      },
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('UserRealName/edit') && ~[0,row.tenant_id].indexOf(_config('this_tenant.id'))
      can_edit = can_edit && row.status==0;
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      iframe('user_real_name/edit?'+s94Mjs.param_encode(param))
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
